//package com.sunxd.zjmh;
//
//import org.apache.pdfbox.pdmodel.PDDocument;
//import org.apache.pdfbox.text.PDFTextStripper;
//import org.springframework.core.io.ClassPathResource;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
//import java.io.IOException;
//import java.io.InputStream;
//
//public class PdfToExcelConverter {
//    public static void main(String[] args) throws FileNotFoundException {
//        File file = new File("C:\\Users\\sunxd\\Desktop\\save.pdf");
//        try (InputStream pdfInputStream = new FileInputStream(file);
//             PDDocument pdfDocument = PDDocument.load(pdfInputStream)) {
//
//            // 使用PDFBox提取文本
//            PDFTextStripper pdfStripper = new PDFTextStripper();
//            String text = pdfStripper.getText(pdfDocument);
//            System.out.println(text);
//
//            // 将文本写入图片，用于OCR
//            Path tempImagePath = Files.createTempFile("pdf_image", ".png");
//            pdfDocument.saveImage(tempImagePath, pdfDocument.getPage(0));
//
////            // 使用Tesseract OCR识别图片中的文本
////            String ocrResult = new Tesseract().doOCR(tempImagePath.toFile());
////
////            // 使用Apache POI创建Excel工作簿并写入文本
////            Workbook workbook = new XSSFWorkbook();
////            Sheet sheet = workbook.createSheet("PDF Content");
////
////            Row row = sheet.createRow(0);
////            Cell cell = row.createCell(0);
////            cell.setCellValue(ocrResult);
////
////            // 写入Excel文件
////            Files.deleteIfExists(Paths.get(excelFilePath));
////            try (InputStream excelInputStream = Files.newInputStream(Paths.get(excelFilePath))) {
////                workbook.write(excelInputStream);
////            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public void convertPdfToExcel(String pdfFilePath, String excelFilePath) throws IOException {
//        try (InputStream pdfInputStream = new ClassPathResource("C:\\Users\\sunxd\\Desktop\\save.pdf").getInputStream();
//             PDDocument pdfDocument = PDDocument.load(pdfInputStream)) {
//
//            // 使用PDFBox提取文本
//            PDFTextStripper pdfStripper = new PDFTextStripper();
//            String text = pdfStripper.getText(pdfDocument);
//            System.out.println(text);
//
//            // 将文本写入图片，用于OCR
////            Path tempImagePath = Files.createTempFile("pdf_image", ".png");
////            pdfDocument.saveImage(tempImagePath, pdfDocument.getPage(0));
//
////            // 使用Tesseract OCR识别图片中的文本
////            String ocrResult = new Tesseract().doOCR(tempImagePath.toFile());
////
////            // 使用Apache POI创建Excel工作簿并写入文本
////            Workbook workbook = new XSSFWorkbook();
////            Sheet sheet = workbook.createSheet("PDF Content");
////
////            Row row = sheet.createRow(0);
////            Cell cell = row.createCell(0);
////            cell.setCellValue(ocrResult);
////
////            // 写入Excel文件
////            Files.deleteIfExists(Paths.get(excelFilePath));
////            try (InputStream excelInputStream = Files.newInputStream(Paths.get(excelFilePath))) {
////                workbook.write(excelInputStream);
////            }
//        }
//    }
//}